#ifndef LOGWORKER_H
#define LOGWORKER_H

#include <QObject>
#include <QFile>
#include <QDateTime>

class LogWorker : public QObject
{
    Q_OBJECT
public:
    explicit LogWorker(QObject *parent = nullptr);

    //日志存储参数
    QString header();
    void setHeader(const QString& header);
    QString fileDir();
    void setFileDir(const QString& fileDir);
    QString fileName();
    void setFileName(const QString& fileName);

    //日志备份参数
    QString backupDir();
    void setBackupDir(const QString& dir);
    int maxLineCount();
    void setMaxLineCount(int maxLineCount);
    int maxSize();
    void setMaxSize(int maxSizeMb);

public slots:
    void open();
    void close();
    void write(const QString& text);

private:
    bool isNeedBackup();
    void backup();

private:
    QFile* m_file;

    QString m_fileDir;
    QString m_fileName;
    QString m_header;

    int m_maxLineCount;
    int m_maxSize;
    bool m_enableBackup;
    QString m_backupDir;

    QDateTime m_beginDateTime;
    int m_curWriteSize;
    int m_curWriteLineCount;

    friend class Logger;
};

#endif // LOGWORKER_H
